import store from '@/assets/scripts/store'
import { ACCESS_TOKEN, ACCESS_LOGIN } from '@/store/mutation-types'

export default {
  set: function (key, val = '', timestamp) {
    store.commit('SET_STORAGE', { key, val })
    if (key === ACCESS_TOKEN) {
      // 用户token存浏览器: 用户名+key  this.get(ACCESS_MCHCODE) +
      key = this.get(ACCESS_LOGIN) + '_' + key
      localStorage.setItem(key, val)
    }
  },
  get: function (key, def) {
    if (key === ACCESS_TOKEN) {
      key = this.get(ACCESS_LOGIN) + '_' + key
      return localStorage.getItem(key)
    }
    return store.state.storeStorage[key] || def
  },
  remove: function (key) {
    this.set(key)
  }
}
